// pages/personal/InvitationType/InvitationType.js
var utils = require('../../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        titleName:"",
        currentPage:1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that=this;
        if (options.type==1){
            that.data.titleName ="普通用户（人）"
        }
        if (options.type == 2) {
            that.data.titleName = "超级会员（人）"
        }
        that.setData({
            titleName:that.data.titleName,
            ordernum: options.ordernum,
            type:options.type
        })
        that.myInvitationTap(that.data.currentPage)
    },
    myInvitationTap: function (currentPage){
        var that=this;
        utils.showLoading();
        utils.http("/api/v1/member/my_invitation", { type:that.data.type,currentPage},function(res){
            utils.hideLoading();
            var allpost = that.data.info;
            if (allpost == undefined) {
                allpost = [];
            }
            for (var i in res.datas) {
                allpost.push(res.datas[i]);
            }
            if (res.datas.length < 10) {
                that.setData({
                    tishi_title: '已加载全部',
                });
            } else {
                that.setData({
                    tishi_title: '加载更多',
                });
            }
            that.setData({
                info: allpost,
                ready: res.datas.length == 0 ? 1 : 2,
            })
        })
    },
    /**
* 页面上拉触底事件的处理函数
*/
    onReachBottom: function () {
        var that = this;
        if (that.data.ready == 2) {
            var page = that.data.currentPage + 1
            that.setData({
                currentPage: page,
            })
            that.myInvitationTap(that.data.type,page)
        }

    },
})